package com.example.catand2mousegame;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class HelpView extends SurfaceView implements SurfaceHolder.Callback {
	MainGame m_MgActivity;
	Paint m_Paint;
	Bitmap m_Background;
	Bitmap m_Ok;

	public HelpView(MainGame actvity) {
		super(actvity);
		this.m_MgActivity = actvity;
		this.getHolder().addCallback(this);
		m_Paint = new Paint();
		m_Paint.setAntiAlias(true);
		initBitmap();
	}

	public void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		canvas.drawBitmap(m_Background, 0, 0, m_Paint);
		canvas.drawBitmap(m_Ok, 20, 440, m_Paint);
	}

	public boolean onTouchEvent(MotionEvent e) {
		float x = e.getX();
		float y = e.getY();

		switch (e.getAction()) {
		case MotionEvent.ACTION_UP:
			if (x >= 20 && x <= 120 && y >= 440 && y <= 475) {
				m_MgActivity.m_Hder.sendEmptyMessage(AssemblyPublic.LM_MENU);
			}
		}
		return true;
	}

	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
	}

	public void surfaceCreated(SurfaceHolder holder) {
		Canvas canvas = holder.lockCanvas();
		try {
			synchronized (holder) {
				onDraw(canvas);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (canvas != null) {
				holder.unlockCanvasAndPost(canvas);
			}
		}
	}

	public void surfaceDestroyed(SurfaceHolder holder) {

	}

	private void initBitmap() {
		m_Background = BitmapFactory.decodeResource(
				m_MgActivity.getResources(), R.drawable.info);
		m_Ok = BitmapFactory.decodeResource(m_MgActivity.getResources(),
				R.drawable.ok);

	}

}
